import logging

import os

import pygame
import pygame.locals

SCREENRECT = pygame.locals.Rect(0, 0, 640, 480)

class DummySound:

    def play(self):
        pass

    def stop(self):
        pass


def load_image(file, convert=True):
    filepath = os.path.join('.', 'data', 'images', file)
    try:
        surface = pygame.image.load(filepath)
    except pygame.error:
        raise SystemExit('Could not load image "%s": %s' % (filepath, pygame.get_error()))

    return convert and surface.convert() or surface

def load_sound(file):
    if pygame.mixer is None:
        return DummySound()

    filepath = os.path.join('.', 'data', 'sounds', file)
    try:
        return pygame.mixer.Sound(file)
    except pygame.error:
        logging.error('Could not load sound "%s": %s' % (filepath, pygame.get_error()))
        return DummySound()


